package dal.object;

import java.awt.image.BufferedImage;
import java.util.Vector;

import dal.FileIO;
import gui.GameConstants;

public class Ball extends ContinuousMapObject {
	private static int dx, dy, ox, oy;
	private BufferedImage sinking[];
	private int size = 11;
	private int current = 0;
	private Vector<Tool> tools;
	
	public Ball(){
		this.img = FileIO.readPic("pic/ball.png");
		oy = ox = img.getWidth() >> 1;
		dx = (GameConstants.picWidth100 >> 1) - ox;
		dy = (GameConstants.picHeight100 >> 1) - oy;
		
		sinking = new BufferedImage[size];
		
		for(int i = 0; i < size; ++i){
			sinking[i] = FileIO.readPic("pic/Labda/" + i + ".png");
		}
		
		tools = new Vector<Tool>();
	}
	
	/**
	 * @return
	 * 	ball's x origo
	 */
	public static int getOx(){
		return ox;
	}
	
	/**
	 * @return
	 * 	ball's y origo
	 */
	public static int getOy(){
		return oy;
	}
	
	/**
	 * @return
	 * 	scalar for moving the ball in the center of a hexagon
	 */
	public static int getDx(){
		return dx;
	}
	
	/**
	 * @return
	 * 	scalar for moving the ball in the center of a hexagon
	 */
	public static int getDy(){
		return dy;
	}
	
	/**
	 * @return
	 * 	ball's radius
	 */
	public static int getRadius(){
		return ox;
	}

	/**
	 * @return
	 * 	true if the ball has sunk
	 */
	public BufferedImage next() {
		if(current < size){
			return sinking[current++];
		} else {
			return null;
		}
	}

	/**
	 * resets the ball
	 */
	public void reset() {
		current = 0;
	}
	
	/**
	 * @param tool
	 * 	activates a tool
	 */
	public void addTool(Tool tool){
		tools.add(tool);
	}
	
	/**
	 * @param c
	 * 	class of a Tool
	 * @return
	 * 	true if the Tool is activated
	 */
	public boolean hasTool(Class<?> c){		
		for(int i = 0; i < tools.size(); ++i){
			if(c.isAssignableFrom(tools.get(i).getClass())){
				return true;
			}
		}
		
		return false;
	}
}